package com.example.knowledgeget1.KnowtCommon.Service;

import com.example.knowledgeget1.KnowtCommon.Entity.Like;
import com.example.knowledgeget1.KnowtCommon.Entity.LikeId;
import com.example.knowledgeget1.KnowtCommon.Repository.LikeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LikeService {
    @Autowired
    private LikeRepository likeRepository;

    public boolean addLike(Long stuId, Long knowId) {
        LikeId likeId = new LikeId(stuId, knowId);
        if (!likeRepository.existsById(likeId)) {
            Like like = new Like();
            like.setId(likeId);
            likeRepository.save(like);
            return true;
        }
        return false;
    }
}